#include "EpilNativeFunctionObject.h"
#include "EpilInterpreter.h"
#include <iomanip>

using namespace std;


EpilNativeFunctionObject::EpilNativeFunctionObject( EpilInterpreter * interpreter )
: EpilFunctionObject( interpreter )
{
}


EpilNativeFunctionObject::~EpilNativeFunctionObject()
{
}


tstring EpilNativeFunctionObject::ToString() const
{
	tstringstream ret;
	ret << t("Function: 0x") << m_function;
	return ret.str();
}


bool EpilNativeFunctionObject::operator==( EpilNativeFunction rhs ) const
{
	return m_function == rhs;
}


bool EpilNativeFunctionObject::operator==( const EpilObject & rhs ) const
{
	if( rhs.GetType() != EOT_Function )
	{
		return false;
	}
	const EpilFunctionObject & function = static_cast<const EpilFunctionObject &>( rhs );

	if( function.GetFunctionType() != this->GetFunctionType() )
	{
		return false;
	}
	const EpilNativeFunctionObject & rhsFunction = static_cast<const EpilNativeFunctionObject &>( function );
	return this->GetFunction() == rhsFunction.GetFunction();
}


EpilObjectVector EpilNativeFunctionObject::Invoke( const EpilObjectVector & params ) const
{
	EpilObjectVector rets = m_function( this->GetInterpreter(), params );
	if( rets.empty() )
	{
		rets.push_back( this->GetInterpreter()->CreateNilObject() );
	}
	return rets;
}